

import 'package:dio/dio.dart';
import 'package:connectivity/connectivity.dart';
import '../code.dart';
import '../code.dart';
import '../result_data.dart';
///    author : leo
///    e-mail : jkliao@yeah.net
///    date   : 2020-03-29
///    desc   :
 class InterceptorNetwork extends InterceptorsWrapper {
  final Dio _dio;
  InterceptorNetwork(this._dio);

  @override
  onRequest(RequestOptions options) async {
    var connectivityResult = await (Connectivity().checkConnectivity());
    if (connectivityResult == ConnectivityResult.none) {
      return _dio.reject(ResultData(Code.NETWORK_NONE, ''));
    }

    if (connectivityResult == ConnectivityResult.mobile) {
      // I am connected to a mobile network.
    } else if (connectivityResult == ConnectivityResult.wifi) {
      // I am connected to a wifi network.
    }
    options.connectTimeout = 15 * 1000;
    options.receiveTimeout = 15 * 1000;

    return options;
  }
 }